<div class="layui-fluid layui-anim febs-anim" id="businesses-resolveException" lay-title="解析异常管理">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="resolveException-table-form">
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                            <legend style="font-size: 15px; font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">开始时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="startDate" id="dtpStartDate_ResolveException" lay-verify="date"
                                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">结束时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="endDate" id="dtpEndDate_ResolveException" lay-verify="date"
                                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">触发方式</label>
                                        <div class="layui-input-inline">
                                            <select name="triggerType" lay-verify="" id="cboTriggerType_ResolveException">
                                                <option value="0" selected>请选择</option>
                                                <option value="62" >定时器同步</option>
                                                <option value="63" >手动同步</option>
                                                <option value="64" >自动推送</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">请求人</label>
                                        <div class="layui-input-inline">
                                            <select name="reqUserId" lay-verify="required" lay-search="" id="cboReqUserId_ResolveException">
                                                <option value="-2" selected >请选择</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query_ResolveException">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset_ResolveException">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <!--                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more">-->
                                <!--                                    <i class="layui-icon">&#xe875;</i>-->
                                <!--                                </div>-->
                            </div>
                        </div>
                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">

                            <div class="layui-row">


                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="export">
                                    <i class="layui-icon layui-icon-export">导出</i>
                                </div>
                            </div>
<!--                            <div style="margin:10px;">-->

<!--                            </div>-->
                        </blockquote>
                    </form>
                    <table lay-filter="resolveExceptionTable" lay-data="{id: 'resolveExceptionTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="resolveException-option">
    <a lay-event="detail">
        <i class="layui-icon febs-edit-area febs-green">&#xe7a5;</i>
    </a>

</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'febs', 'laydate'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            laydate = layui.laydate,
            $view = $('#businesses-resolveException'),
            $query = $view.find('#query_ResolveException'),
            $add = $view.find('#add'),
            $reset = $view.find('#reset_ResolveException'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createDate', type: null},
            tableIns;


        form.render();

        /*
        *  开始日期、结束日期控件渲染
        * */
        laydate.render({
            elem: '#dtpStartDate_ResolveException',
        });
        laydate.render({
            elem: '#dtpEndDate_ResolveException'
        });



        initTable();

        // dropdown.render({
        //     elem: $view.find('.action-more'),
        //     click: function (name, elem, event) {
        //         let checkStatus = table.checkStatus('resolveExceptionTable');
        //         if (name === 'add') {
        //             febs.modal.open('新增院校', 'resolveException/add', {
        //                 btn: ['提交', '重置'],
        //                 area: $(window).width() <= 750 ? '95%' : '50%',
        //                 yes: function (index, layero) {
        //                     $('#resolveException-add').find('#submit').trigger('click');
        //                 },
        //                 btn2: function () {
        //                     $('#resolveException-add').find('#reset_ResolveException').trigger('click');
        //                     return false;
        //                 }
        //             });
        //         }
        //         if (name === 'delete') {
        //             if (!checkStatus.data.length) {
        //                 febs.alert.warn('请选择需要删除的院校');
        //             } else {
        //                 febs.modal.confirm('删除院校', '确定删除该院校？', function () {
        //                     let resolveExceptionIds = [];
        //                     layui.each(checkStatus.data, function (key, item) {
        //                         resolveExceptionIds.push(item.id)
        //                     });
        //                     deleteresolveExceptions(resolveExceptionIds.join(','));
        //                 });
        //             }
        //         }
        //
        //         if (name === 'export') {
        //             let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
        //             params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
        //             params.pageNum = $view.find(".layui-laypage-em").next().html();
        //             febs.download(ctx + 'resolveException/excel', params, '院校信息表.xlsx');
        //         }
        //     },
        //     options: [{
        //         name: 'add',
        //         title: '新增院校',
        //         perms: 'resolveException:add'
        //     }, {
        //         name: 'delete',
        //         title: '删除院校',
        //         perms: 'resolveException:delete'
        //     }, {
        //         name: 'export',
        //         title: '导出Excel',
        //         perms: 'resolveException:export'
        //     }]
        // });

        table.on('tool(resolveExceptionTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                febs.modal.view('异常详情', 'resolveException/detail/' + data.id, {
                    area: $(window).width() <= 750 ? '95%' : '660px'
                });
            }

        });

        table.on('sort(resolveExceptionTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $add.on('click', function () {
            febs.modal.open('新增院校', 'resolveException/add', {
                btn: ['提交', '重置'],
                area: $(window).width() <= 750 ? '95%' : '50%',
                yes: function (index, layero) {
                    $('#resolveException-add').find('#submit').trigger('click');
                },
                btn2: function () {
                    $('#resolveException-add').find('#reset_ResolveException').trigger('click');
                    return false;
                }
            });
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'resolveExceptionTable',
                url: ctx + 'resolveException/list',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'exceptionTime', title: '解析出错时间', minWidth: 100, sort: true},
                    {field: 'detail', title: '触发方式', minWidth: 100},
                    {field: 'userName', title: '请求人'},
                    {title: '操作', toolbar: '#resolveException-option', minWidth: 140}
                ]]
            });
            initCboReqUserId();
        }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
            return params;
        }

        function deleteresolveExceptions(resolveExceptionIds) {
            febs.get(ctx + 'resolveException/delete/' + resolveExceptionIds, null, function () {
                febs.alert.success('删除院校成功');
                $query.click();
            });
        }

        /*
        * 加载请求人下拉菜单
        * */
        function initCboReqUserId() {
//            console.log($("#cboReqUserId_ResolveException").val());
            $.ajax({
                type:"GET",
                url: ctx + 'user/reqUserList',

                success:function (res) {
                    for(var i = 0 ;i < res.length;i++){
                        var htmlContent = "<option value='"+ res[i].userId +"' >" + res[i].username + "</option>";
//                        console.log(htmlContent);
                        $("#cboReqUserId_ResolveException").append(htmlContent);
                    }
                    form.render();
                }
            });
        }

        //按回车搜索
        $(".layui-input").keydown(function (e) {//当按下按键时
            if (e.which == 13) {//.which属性判断按下的是哪个键，回车键的键位序号为13
                $query.click();
            }
        });
    })
</script>